package com.example.danangtravel.Travel;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import com.exam.danangtranel.adapter.TbTravelPointAdapter;
import com.exam.danangtranel.filed.Travel;
import com.example.danangtravel.DataAccess;
import com.example.danangtravel.R;
import com.example.danangtravel.checknetwork;
import com.example.danangtravel.map.RoutePath;

import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.Toast;

public class Travel_Item extends Activity {
	public GridView grid;
	public TbTravelPointAdapter adapter;
	public ArrayList<Travel> array;
	public ImageButton map_travel;
	private checknetwork check;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dulich_main);
		ImageButton im = (ImageButton) findViewById(R.id.im_homdulich);
		im.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		Intent it = getIntent();
		int idget = it.getExtras().getInt("id");
		grid = (GridView) findViewById(R.id.grid);
		try {
			DataAccess data = new DataAccess(this);
			array = new ArrayList<Travel>();
			array = data.getAlTravel(idget);
			data.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		adapter = new TbTravelPointAdapter(this, array);
		grid.setAdapter(adapter);

		map_travel = (ImageButton) findViewById(R.id.btnMapTravel);
		map_travel.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(v.getContext(), "" + array.get(0).getLatitude(),
						1000).show();

				// Bang null latitude va longtitude
				check = new checknetwork(v.getContext());
				// if (check.isOnline()) {
				//
				// Intent i = new Intent(v.getContext(), RoutePath.class);
				// i.putExtra("latitude", array.get(0).getLongitude()); // bi
				// // dao?
				// // nguoc...
				// i.putExtra("longitude", array.get(0).getLatitude()); // bi
				// // dao?
				// // nguoc...
				// v.getContext().startActivity(i);
				// } else
				// Toast.makeText(v.getContext(), "Không có kết nối !", 1000)
				// .show();
			}
		});
	}

}
